
<template>
  <el-container class="homeContainer">
    <el-header>
      <div class="header-left">
        <img src="../assets/logo.png" alt="" />
        <div class="title">电商后台管理系统</div>
      </div>
      <el-button type="success" size="mini" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '300px'">
        <div class="toggles" @click="toggleCollapse">|||</div>
        <el-row>
          <el-col :span="24">
            <el-menu
              :default-active="$route.path"
              class="el-menu-vertical-demo"
              background-color="#333744"
              text-color="#fff"
              active-text-color="#ffd04b"
              :unique-opened="true"
              router
              :collapse="isCollapse"
              :collapse-transition="false"
              @open="handleOpen"
              @close="handleClose"
            >
              <el-submenu
                :index="item.id + ''"
                v-for="item in menuList"
                :key="item.id"
              >
                <template slot="title">
                  <i :class="iconsObj[item.id]"></i>
                  <span>{{ item.authName }}</span>
                </template>
                <el-menu-item
                  v-for="item1 in item.children"
                  :key="item1.id"
                  :index="'/' + item1.path"
                >
                  <i :class="iconsObj1[item1.id]"></i>

                  {{ item1.authName }}
                </el-menu-item>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import HomeAPI from "../http/API/Role"
export default {
  name: "home",
  components: {},
  data() {
    return {
      menuList: [],
      isCollapse: false,
      iconsObj: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      iconsObj1: {
        110: "el-icon-s-check",
        111: "el-icon-user",
        112: "el-icon-setting",
        104: "el-icon-s-grid",
        115: "el-icon-document-copy",
        121: "el-icon-s-data",
        107: "el-icon-edit-outline",
        146: "el-icon-office-building",
      },
    };
  },
  methods: {
    logout() {
      localStorage.removeItem("token");
      this.$router.push("/");
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    handleOpen() {},
    handleClose() {},
  },
  created() {
    HomeAPI.leftMensList(this.menuList).then((res) => {
      // console.log(res);
      if (res.data.meta.status == 200) {
        this.menuList = res.data.data;
      } else {
        this.$message({
          message: "菜单数据获取失败",
        });
      }
    });
  },
};
</script>
<style  scoped>
.el-aside {
  background-color: #333744;
}

.el-main {
  background-color: #eaedf1;
}
.toggles {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
}
.homeContainer {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #373d41;
}
.header-left {
  display: flex;
  align-items: center;
  font-size: 22px;
  color: #fff;
}
.title {
  padding-left: 30px;
}
img {
  width: 60px;
  height: 50px;
  margin-top: 5px;
}
</style>
